<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
 <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html>
  <head>
 
    <title>添加权限</title>
    <meta name="renderer" content="webkit">
    <jsp:include page="header.jsp"></jsp:include>
  </head>
  
  <body>
    <div class="x-body">
        <form action="" method="post" class="layui-form layui-form-pane" id="myForm">
        	<input type="hidden" name="id" value="${role.id}">
                <div class="layui-form-item">
                    <label for="name" class="layui-form-label">
                        <span class="x-red">*</span>角色名
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" id="name" name="roleName" required="" lay-verify="required"
                        autocomplete="off" class="layui-input" value="${role.roleName}" readonly="readonly">
                    </div>
                </div>
                <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label">
                        拥有权限
                    </label>
                    <table  class="layui-table layui-input-block">
                        <tbody>
                        <c:if test="${not empty list}">
      						
                            <tr>
                                <td>
                                    	内容管理
                                    
                                </td>
                                <td>
                                
                                    <div class="layui-input-block">
                                    <c:forEach var="app" items="${list}" varStatus="st">
      									<c:if test="${app.quanFather==1}">
                                        <input name="privilege" type="checkbox" value="${app.id}"> ${app.quanName}
                                        </c:if>
                            	</c:forEach>
                            	
                                    </div>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    	人员管理
                                   
                                </td>
                                <td>
                                    <div class="layui-input-block">
                                     <c:forEach var="app" items="${list}" varStatus="st">
      									<c:if test="${app.quanFather==2}">
                                        <input name="privilege" type="checkbox" value="${app.id}"> ${app.quanName}
                                        </c:if>
                                        </c:forEach>
                                    </div>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    	数据统计
                                   
                                </td>
                                <td>
                                    <div class="layui-input-block">
                                        <c:forEach var="app" items="${list}" varStatus="st">
      									<c:if test="${app.quanFather==3}">
                                        <input name="privilege" type="checkbox" value="${app.id}"> ${app.quanName}
                                        </c:if>
                                        </c:forEach>
                                    </div>
                                </td>
                            </tr>
                            </c:if>
                        </tbody>
                    </table>
                </div>
                <div class="layui-form-item">
                <input type="hidden" name="id" value="${role.id}">
                <button class="layui-btn" lay-submit="" lay-filter="add" id="my_add">增加</button>
              </div>
            </form>
    </div>
    <script>
    $("#my_add").click(function(){
    	var ss =$('#myForm').serialize();
    	$.ajax({
    		url:"/admin/addPrivilege",
    		type: 'post',
    		data: ss,
    		success: function (data){
    			if("ok"==data){
    				layer.alert("角色添加权限成功!", {icon: 6},function () {
    	                // 获得frame索引
    	                var index = parent.layer.getFrameIndex(window.name);
    	                //关闭当前frame
    	                parent.layer.close(index);
    	            });
    			}else{
    				layer.alert("角色添加权限失败!");
    			}
    		}
    	});
    	return false;
    });
        
/* 
          //监听提交
          form.on('submit(add)', function(data){
            console.log(data);
            //发异步，把数据提交给php
            layer.alert("增加成功", {icon: 6},function () {
                // 获得frame索引
                var index = parent.layer.getFrameIndex(window.name);
                //关闭当前frame
                parent.layer.close(index);
            });
            return false;
          });
           */
    </script>
  </body>

</html>